package com.mjkj.demo.core.result;

/**
 * 响应结果生成工具
 * @author cwh
 * @date 2023-01-07
 */
public class ResultGenerator {
    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

    public static Result genSuccessResult() {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE);
    }

    public static <T> Result<T> genSuccessResultMessage(String message) {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(message);
    }

    public static <T> Result<T> genSuccessMessage(String message) {
        return new Result()
                .setCode(ResultCode.PROMPT)
                .setMessage(message);
    }

    public static <T> Result<T> genSuccessResult(T data) {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE)
                .setData(data);

    }

    public static Result genFailResult(String message) {
        return new Result()
                .setCode(ResultCode.FAIL)
                .setMessage(message);
    }

    public static <T> Result<T> genFailResult(String message, ResultCode resultCode) {
        return new Result()
                .setCode(resultCode)
                .setMessage(message);
    }

    public static <T> Result<T> genFailResult(T data, String message, ResultCode resultCode) {
        return new Result()
                .setCode(resultCode)
                .setMessage(message)
                .setData(data);
    }

    public static <T> Result<T> genFailResult(T data, String message, int code) {
        return (Result<T>) Result.builder()
                .code(code)
                .message(message)
                .data(data)
                .build();
    }
}
